<?php 
namespace Plugin\Controller;
use Common\Controller\BaseController;
class BannerController extends BaseController{
	
	public function index(){
		$this->display();
	}
	
	public function edit(){
		if(I("id")){
			$this->info = M("Banners")->find(I("id"));
		}
		$this->display();
	}
	
	public function edit_post(){
		$m = M("Banners");
		if(I('post.id')){
			$data = I('post.');
			$data['update_time'] = time();
			$res = $m->data($data)->save();
		}else{
			$data = I('post.');
			$data['update_time'] = time();
			$res = $m->data($data)->add();
		}
		if($res){
			_apiReturn(1,'success');
		}else{
			_apiReturn(0,'error');
		}
	}
	
	public function del(){
		$this->_del(M("Banners"), I("id"));
	}
	
	public function getdata(){
	
		$p = I('p') ? I('p') : 1;
		$row = I('row') ? I('row') : 10;
	
		$m = M('Banners');
		$data['data'] = $m->where($map)->page($p,$row)->select();
		//$data['sql'] = $m->_sql();
		$data['page']['total'] = $m->where($map)->count();
		$data['page']['cur'] = $p;
		$data['page']['row'] = $row;
	
		_apiReturn(1, L('success'), $data, $url); //数据获取成功
	}
	
	public function getimgdata(){
	
		$p = I('p') ? I('p') : 1;
		$row = I('row') ? I('row') : 10;
	
		$m = M('BannerImgs');
		$map['pid'] = $_REQUEST['pid'];
		$data['data'] = $m->where($map)->page($p,$row)->select();
		$data['sql'] = $m->_sql();
		$data['page']['total'] = $m->where($map)->count();
		$data['page']['cur'] = $p;
		$data['page']['row'] = $row;
	
		_apiReturn(1, L('success'), $data, $url); //数据获取成功
	}
	
	public function img_list(){
		$this->display();
	}
	
	public function img_edit(){
		$this->pid = I("pid");
		if(I("id")){
			$this->info = M("BannerImgs")->find(I("id"));
			$this->pid = $this->info['pid'];
		}
		$this->display();
	}
	
	public function img_edit_post(){
		$m = M('BannerImgs');
		//编辑
		if(I('post.id')){
			$data = I('post.');
			$data['update_time'] = time();
			$res = $m->data($data)->save();
			//新增
		}else{
			$data = I('post.');
			$data['update_time'] = time();
			$res = $m->data($data)->add();
		}
		if($res){
			_apiReturn(1,'success');
		}else{
			_apiReturn(0,'failed');
		}
	}
	
	public function img_del(){
		$this->_del(M("BannerImgs"), I("id"));
	}
}
?>